package com.example.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author DestinyCc
 * @date 2022/4/19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AvgQuality implements Serializable {
    /**
     * 可靠性
     */
    Double reliability;
    /**
     * 复杂性
     */
    Double complexity;

    /**
     * 继承性
     */
    Double inheritance;

    /**
     * 可维护性
     */
    Double maintainability;

    /**
     * 可读性
     */
    Double readability;

    /**
     * 可复用性
     */
    Double reuseablity;

    /**
     * 可测试性
     */
    Double testability;

    /**
     * 可扩展性
     */
    Double extendability;

    /**
     * 安全性
     */
    Double security;

    public AvgQuality(String reliability){
        this.reliability = Double.parseDouble(reliability);
        this.complexity = (double) 0;
        this.extendability = (double) 0;
        this.inheritance = (double) 0;
        this.maintainability = (double) 0;
        this.readability = (double) 0;
        this.reuseablity = (double) 0;
        this.security = (double) 0;
        this.testability = (double) 0;
    }

    public void addOneValue(CodeQuality quality){
        this.complexity += quality.getComplexity();
        this.extendability += quality.getExtendability();
        this.inheritance += quality.getInheritance();
        this.maintainability += quality.getMaintainability();
        this.readability += quality.getReadability();
        this.reuseablity += quality.getReuseablity();
        this.security += quality.getSecurity();
        this.testability += quality.getTestability();
    }

    public AvgQuality getAvgCodeQuality(int fileNumber){
        return new AvgQuality(this.reliability,
                this.complexity/fileNumber,
                this.inheritance/fileNumber,
                this.maintainability/fileNumber,
                this.readability/fileNumber,
                this.reuseablity/fileNumber,
                this.testability/fileNumber,
                this.extendability/fileNumber,
                this.security/fileNumber);
    }
}
